﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace 互斥锁1
{
    internal class Program
    {
        public static Mutex mutex = new Mutex(false,"muMutex");
        static void Main(string[] args)
        {
            for (int i = 0; i <10000; i++)
            {
                Thread.Sleep(500);
                if (mutex.WaitOne())
                {
                    Console.WriteLine(mutex.Handle.ToString());
                    Console.WriteLine(mutex.SafeWaitHandle.IsInvalid);
                    Console.WriteLine(mutex.SafeWaitHandle);
                    
                    Console.WriteLine(mutex.SafeWaitHandle.IsClosed);
                    Console.WriteLine("互斥锁1-我被别人锁啦");
                    mutex.ReleaseMutex();
                }
              
            }
        }
    }
}
